package com.ai.zhly.task;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.apache.log4j.Logger;
import com.ai.dmc.index.common.InitParam;
import com.ai.dmc.index.common.bean.AreaBean;
import com.ai.dmc.index.common.bean.TmpXqBean;
import com.ai.dmc.index.common.cache.AreaCache;
import com.ai.dmc.index.common.cache.DataTimeCache;
import com.ai.dmc.index.common.util.DateUtil;
import com.ai.zhly.service.ICommonService;
import com.ai.zhly.service.IConvertService;
import com.ai.zhly.util.ConvertUtil;


/**
 * @Description : area任务
 * 
 * @author : wucm
 * @date : 2015年8月28日 上午11:16:10
 * @version V1.0
 * 
 */
public class ConvertTask {
	private static Logger logger = Logger.getLogger(ConvertTask.class);
	private static boolean executeFlagArea = false;// 防止多次执行
	private String tableName = "dim_table";
	
	private IConvertService convertService;
	
	public IConvertService getConvertService() {
		return convertService;
	}

	public void setConvertService(IConvertService convertService) {
		this.convertService = convertService;
	}

	public void execute() {
		if (executeFlagArea) {
			return;
		}

		// 检查数据是否有更新
//		if (!checkTime()) {
//			return;
//		}

		executeFlagArea = true;

		logger.debug("小区边界任务开始时间："
				+ DateUtil.getInstance().getToday("yyyy-MM-dd hh:mm:ss"));

		// 获取小区边界
		try {
			loadXqGeo();
		} catch (Exception e) {
			e.printStackTrace();
		}
		

		logger.debug("小区边界任务结束时间："
				+ DateUtil.getInstance().getToday("yyyy-MM-dd hh:mm:ss"));
		executeFlagArea = false;
	}


	/**
	 * 
	 * @Description : 取小区边界
	 * 
	 * @return JSONObject
	 * 
	 * @author : wucm
	 * @date : 2015年11月8日 下午4:28:13
	 * 
	 */
	private void loadXqGeo() {
		List<TmpXqBean> oldList = convertService.queryXqInfo();
		
		TmpXqBean newBean = new TmpXqBean();
		for (TmpXqBean oldBean : oldList) {
			newBean = ConvertUtil.convert(oldBean);
			convertService.updateXqInfo(newBean);
			System.out.println("更新小区ID："+newBean.getXqId());
		}
		System.out.println("=========================");
	}

	
}
